﻿using nplJobsCommon.Employeer;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nplJobsDAL.Insert
{
   public class InsertContactPerson : DataAccessBase
    {
       public int lastEmployeerContactPersonID = 0;
        public string checkUnique;

        public EmployeerContactPerson EmployeerContactPerson { get; set; }

        public InsertContactPerson()
        {
            StoredProcedureName = StoredProcedure.Name.spInsertEmployeerContactPerson.ToString();
        }

        public void invoke()
        {
            InsertEmployeerContactPersonDataParameters insertEmployeerDataParameters = new InsertEmployeerContactPersonDataParameters(this.EmployeerContactPerson);
            DataBaseHelper dbHelper = new DataBaseHelper(StoredProcedureName);
            dbHelper.Parameters = insertEmployeerDataParameters.Parameters;
            object lastEmployeerID = dbHelper.RunScalar();

            if (lastEmployeerID != null)
            {
                this.lastEmployeerContactPersonID = int.Parse(lastEmployeerID.ToString());
            }
        }
    }

    #region SQL parameters for employeer contact person insert data
    public class InsertEmployeerContactPersonDataParameters
    {
        public long lastContactPersonID;
        private SqlParameter[] _parameters;

        public InsertEmployeerContactPersonDataParameters(EmployeerContactPerson employeercontactperson)
        {
            this.EmployeerContactPerson = employeercontactperson;
            Build();
        }

        #region spAddContact parameters
        /*
         
         */
        #endregion

        private void Build()
        {
            SqlParameter[] parameters = 
                {
                    new SqlParameter("@FirstName", EmployeerContactPerson.FirstName),
                    new SqlParameter("@LastName", EmployeerContactPerson.LastName),
                    new SqlParameter("@Email", EmployeerContactPerson.Email),
                    new SqlParameter("@TitleID", EmployeerContactPerson.TitleID),
                    new SqlParameter("@DesignationID", EmployeerContactPerson.DesignationID),
                    new SqlParameter("@ContactNumber", EmployeerContactPerson.ContactNumber ),
                    new SqlParameter("@AlternativeNumber", EmployeerContactPerson.AlternativeNumber ),
                    new SqlParameter("@EmployeerID", EmployeerContactPerson.EmployeerID),
                    new SqlParameter("@ContactPersonID",lastContactPersonID) { Direction=System.Data.ParameterDirection.ReturnValue},

                };

            Parameters = parameters;
        }

        public EmployeerContactPerson EmployeerContactPerson { get; set; }

        public SqlParameter[] Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }
    }
    #endregion
}
